// 导入axios
import axios from 'axios';

/**
 * 获取商品列表
 * @param {*} commodity 商品对象
 * @param {*} page 当前页码，默认值为1页
 * @param {*} maxResult 每页显示数量，默认值是10
 */
export async function getCommodityList(commodityName,commodityType,page=1,maxResult=10){
    // 使用代理 远程访问tomcat里面的java项目api
   let resp = await axios.get('/api/pet_sys/commodity.do',{
        params: {
            commodityName,
            commodityType,
            page,
            maxResult,
            // needContent:1,
            // needAllList:false
        }
    })
    console.log("==getCommodityList==");
    console.log(resp);
    return resp;
}
/**
 * 删除商品
 * @param {} commodityId 
 */
export async function deleteCommodity(commodityId){
    // 使用代理 远程访问tomcat里面的java项目api
   let resp = await axios.get('/api/pet_sys/commodity.do',{
        params: {
            method:'deleteCommodity',
            commodityId,
           
            // needContent:1,
            // needAllList:false
        }
    })
    console.log("==deleteCommodity==");
    console.log(resp);
    return resp;
}
/**
 * 添加商品
 * @param {*} ruleForm 商品表格
 */
export async function addCommodity(ruleForm){
    // 使用代理 远程访问tomcat里面的java项目api
   let resp = await axios.get('/api/pet_sys/commodity.do',{
        params: {
            method:'insertCommodity',
            commodityName: ruleForm.commodityName,
            commodityType: ruleForm.commodityType,
            commodityMaterial: ruleForm.commodityMaterial,
            commodityWeightStandard: ruleForm.commodityWeightStandard,
            commodityStandard: ruleForm.commodityStandard,
            commodityPackage: ruleForm.commodityPackage,
            commodityTaste: ruleForm.commodityTaste,
            commoditySpecial: ruleForm.commoditySpecial,
            commodityPrice: ruleForm.commodityPrice,
            commodityImages: ruleForm.commodityImages,
            commodityOrigin: ruleForm.commodityOrigin,
            commodityFactoryTime: ruleForm.commodityFactoryTime,
            commodityShelf: ruleForm.commodityShelf,
            commoditySpecialMsg: ruleForm.commoditySpecialMsg,
        }
    })
    console.log("==addCommodity==");
    console.log(resp);
    return resp;
}
/**
 * 修改商品
 * @param {*} commodityId 
 * @param {*} ruleForm 
 */
export async function updateCommodity(commodityId,ruleForm){
    // 使用代理 远程访问tomcat里面的java项目api
   let resp = await axios.get('/api/pet_sys/commodity.do',{
        params: {
            method:'updateCommodity',
            commodityId,
            commodityName: ruleForm.commodityName,
            commodityType: ruleForm.commodityType,
            commodityMaterial: ruleForm.commodityMaterial,
            commodityWeightStandard: ruleForm.commodityWeightStandard,
            commodityStandard: ruleForm.commodityStandard,
            commodityPackage: ruleForm.commodityPackage,
            commodityTaste: ruleForm.commodityTaste,
            commoditySpecial: ruleForm.commoditySpecial,
            commodityPrice: ruleForm.commodityPrice,
            commodityImages: ruleForm.commodityImages,
            commodityOrigin: ruleForm.commodityOrigin,
            commodityFactoryTime: ruleForm.commodityFactoryTime,
            commodityShelf: ruleForm.commodityShelf,
            commoditySpecialMsg: ruleForm.commoditySpecialMsg,
        }
    })
    console.log("==updateCommodity==");
    console.log(resp);
    return resp;
}

export async function getCommodityById(commodityId){
    // 使用代理 远程访问tomcat里面的java项目api
   let resp = await axios.get('/api/pet_sys/commodity.do',{
        params: {
            method:'getCommodityById',
            commodityId,
            // needContent:1,
            // needAllList:false
        }
    })
    console.log("==getCommodityById==");
    console.log(resp);
    return resp;
}